﻿<%@ Page Title="" Language="C#" MasterPageFile="~/master_form.master" AutoEventWireup="true" CodeFile="nhap_diem_ts.aspx.cs" Inherits="App_Form_nhap_diem" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <script type="text/javascript" src="../js/plugin/CellEditing.js"></script>

    <script type="text/javascript">
        Ext.Loader.setConfig({
            enabled: true
        });
        Ext.Loader.setPath('Ext.ux', '../ux');

        Ext.require(['*']);

        Ext.require([
    'Ext.selection.CellModel',
    'Ext.grid.*',
    'Ext.data.*',
    'Ext.util.*',
    'Ext.state.*',
    'Ext.form.*',
    'Ext.grid.Panel',
        'Ext.layout.container.Column'
        ]);


        Ext.onReady(function () {

            Ext.QuickTips.init();

            var bd = Ext.getBody();

            var gridForm = Ext.create('Ext.form.Panel', {
                id: 'company-form',
                frame: true,
                bodyPadding: 5,
                width: 1150,
                layout: {
                    type: 'table',
                    columns: 1
                },
                fieldDefaults: {
                    labelAlign: 'left',
                    msgTarget: 'side'
                },

                items: [
                    {
                        columnWidth: '100%',
                        margin: '0 0 0 10',
                        xtype: 'fieldset',
                        title: 'Thông tin môn học',
                        width: 1150,
                        columnWidth: 1,
                        layout: 'anchor',
                        defaults: {
                            labelWidth: 100
                        },
                        defaultType: 'textfield',
                        items: [
                             {
                                 xtype: 'fieldcontainer',
                                 combineErrors: false,
                                 layout: {
                                     type: 'hbox',
                                     defaultMargins: { top: 0, right: 5, bottom: 0, left: 0 }
                                 },
                                 defaults: {
                                     hideLabel: true
                                 },
                                 items: [
                                 { xtype: 'displayfield', width: 70, value: 'Năm TS :' },
                                 {
                                     width: 150, xtype: 'combo', value: 'I', emptyText: 'Chọn năm học',
                                     triggerAction: 'all', forceSelection: true, editable: false,
                                     id: 'nam_hoc', name: 'nam_hoc', displayField: 'ten', valueField: 'id',
                                     queryMode: 'local',
                                     listeners: {
                                         select: function (combo, record, index) {
                                             if (record.length > 0) {
                                                 var id_nam = record[0].get('id');
                                                 var b_khoi = Ext.getCmp("khoithi").getValue();
                                                 b_khoi = (b_khoi == null ? "" : b_khoi);
                                                 wsinh_vien.Fs_DIEM_TUYEN_SINH_PH(id_nam, b_khoi, diem_ts_P_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                             }
                                         }
                                     }
                                 },
                                  { xtype: 'displayfield', width: 70, value: 'Khối thi :' },
                                  {
                                      width: 150, xtype: 'combo', triggerAction: 'all', emptyText: 'Chọn khối thi',
                                      forceSelection: true, editable: false, id: 'khoithi',
                                      name: 'khoithi', displayField: 'Ten', valueField: 'Ma_khoi',
                                      listeners: {
                                          select: function (combo, record, index) {
                                              if (record.length > 0) {
                                                  var b_khoi = record[0].get('Ma_khoi');
                                                  var id_nam = Ext.getCmp("nam_hoc").getValue();
                                                  wsinh_vien.Fs_DIEM_TUYEN_SINH_PH(id_nam, b_khoi, diem_ts_P_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                              }
                                          }
                                      }
                                  },
                                  { xtype: 'displayfield', width: 70, value: 'Phòng thi :' },
                                  {
                                      xtype: 'combo', emptyText: 'Chọn phòng thi', triggerAction: 'all',
                                      forceSelection: true, editable: false,
                                      id: 'phong_thi', name: 'phong_thi', displayField: 'ten', valueField: 'id', queryMode: 'local'
                                  },
                                 { xtype: 'displayfield', width: 70, value: 'Môn thi :' },
                                  {
                                      xtype: 'combo', emptyText: 'Chọn phòng thi', triggerAction: 'all',
                                      forceSelection: true, editable: false,
                                      id: 'monthi', name: 'monthi', displayField: 'Ten', valueField: 'ID', queryMode: 'local'
                                  },
                                 {
                                     name: 'tim',
                                     xtype: 'button',
                                     width: 80,
                                     icon: '../../shared/icons/fam/find.png',
                                     text: 'Tìm', margin: '0 5 0 5',
                                     handler: function () {
                                         var id_nam = Ext.getCmp("nam_hoc").getValue(), b_khoi = Ext.getCmp("khoithi").getValue(),
                                              b_phong = Ext.getCmp("phong_thi").getValue(), b_monthi = Ext.getCmp("monthi").getValue();
                                         wsinh_vien.Fs_TUYEN_SINH_DIEM_TIM(id_nam, b_khoi, b_phong, b_monthi, KB_TIM_P_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                     }
                                 },
                                    {
                                        name: 'add',
                                        xtype: 'button',
                                        margin: '0 5 0 5',
                                        width: 80,
                                        icon: '../../shared/icons/fam/add.gif',
                                        text: 'Thêm mới',
                                        handler: function () {
                                            b_monthi = Ext.getCmp("monthi").getValue();
                                            if (b_monthi == "") return alert("Chưa chọn môn");
                                            var b_tinhdiem = Ext.getCmp('tinhdiem');
                                            var a_gtriGrid = new Array();
                                            var i = 0;
                                            b_tinhdiem.getStore().each(function (record) {
                                                if (NVL(record.get("diem"), "") != "") {
                                                    a_gtriGrid[i] = [NVL(record.get("id_diem"), "0"), record.get("id_ts"), NVL(record.get("diem"), "0")];
                                                    i++;
                                                }
                                            });
                                            wsinh_vien.Fs_TUYEN_SINH_DIEM_NH(b_monthi, a_gtriGrid, nhaodiemP_KQ, P_LOI_CSDL, P_LOI_TGIAN);
                                        }
                                    }]
                             }]
                    },
                    {
                        columnWidth: '100%',
                        xtype: 'gridpanel',
                        margin: '5 0 0 10',
                        id: 'tinhdiem',
                        store: null,
                        height: 450,
                        plugins: Ext.create('Ext.grid.plugin.CellEditing', {
                            clicksToEdit: 1
                        }),
                        layout: {
                            defaultMargins: { top: 0, right: 5, bottom: 0, left: 5 }
                        },
                        title: 'Danh sách học sinh',
                        columns: [
                            { id: 'id_diem', flex: 1, hidden: true, hideable: false, dataIndex: 'id_diem' },
                            { id: 'id_tsb', flex: 1, hidden: true, hideable: false, dataIndex: 'id_ts' },
                            { id: 'hoten', text: 'Họ và tên', width: 150, flex: 1, sortable: true, dataIndex: 'hoten' },
                            { id: 'ngay_sinh', text: 'Ngày sinh', width: 80, flex: 1, sortable: true, dataIndex: 'ngay_sinh' },
                            { id: 'noi_sinh', text: 'Nơi sinh', width: 150, flex: 1, sortable: true, dataIndex: 'noi_sinh' },
                            {
                                text: 'điểm',
                                width: 100,
                                sortable: true,
                                dataIndex: 'diem',
                                editor: {
                                    xtype: 'numberfield',
                                    decimalSeparator: '.',
                                    hideTrigger: true,
                                    allowBlank: false
                                }
                            }
                        ]
                    }],
                renderTo: bd
            });
            wsinh_vien.Fs_DIEM_TUYEN_SINH_TTCHUNG(P_LOAD_TTCHUNG, P_LOI_CSDL, P_LOI_TGIAN);
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <script type="text/javascript">

        function P_LOAD_TTCHUNG(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            else {
                var a_kq = b_kq.split('@');
                var b_chuoi1 = CH_JSON(a_kq[0]),
                    b_chuoi2 = CH_JSON(a_kq[1]);

                var a_data1 = Ext.create('Ext.data.Store', {
                    fields: ['id', 'ten'],
                    data: b_chuoi1
                });

                var a_data2 = Ext.create('Ext.data.Store', {
                    fields: ['Ma_khoi', 'Ten'],
                    data: b_chuoi2
                });

                var cd = Ext.getCmp('nam_hoc');
                cd.bindStore(a_data1);

                var b_hk = Ext.getCmp("khoithi");
                b_hk.bindStore(a_data2);

            }
        }
        function diem_ts_P_KQ(b_kq)
        {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            var a_kq = b_kq.split("@");

            var b_chuoi1 = CH_JSON(a_kq[0]);
            var a_data1 = Ext.create('Ext.data.Store', {
                fields: ['id', 'ten'],
                data: b_chuoi1
            });
            var d = Ext.getCmp('phong_thi');
            d.bindStore(a_data1);

            var b_chuoi2= CH_JSON(a_kq[1]);
            var a_data2 = Ext.create('Ext.data.Store', {
                fields: ['ID', 'Ten'],
                data: b_chuoi2
            });

            var b_hk = Ext.getCmp("monthi");
            b_hk.bindStore(a_data2);
        }
        function KB_TIM_P_KQ(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            else {
                var b = Ext.getCmp('tinhdiem');
                var b_chuoi1 = CH_JSON(b_kq);

                var store = Ext.create('Ext.data.JsonStore', {
                    fields: ["id_diem", "id_ts", "hoten", "ngay_sinh", "noi_sinh", "diem"],
                    data: b_chuoi1
                });

                b.bindStore(store);
            }
        }
      
        function nhaodiemP_KQ(b_kq) {
            if (Fb_LOI_KTRA(b_kq)) {
                form_P_LOI(b_kq);
                return;
            }
            alert("Nhập thành công");
            //KB_TIM_P_KQ(b_kq);
        }
       
    </script>
</asp:Content>

